package com.flashcash.solu.common.network;

import android.support.annotation.Nullable;

import com.flashcash.kotlin.data.ActivityInfoBean;
import com.flashcash.kotlin.data.BankBean;
import com.flashcash.kotlin.data.BannerUrlBean;
import com.flashcash.kotlin.data.BasicAck;
import com.flashcash.kotlin.data.CouponBean;
import com.flashcash.kotlin.data.DisplayBean;
import com.flashcash.kotlin.data.HelpCenterUrlAndHotlineBean;
import com.flashcash.kotlin.data.InviteeBean;
import com.flashcash.kotlin.data.InviteePersonBean;
import com.flashcash.kotlin.data.LoanRange;
import com.flashcash.kotlin.data.LoaningAmoutBean;
import com.flashcash.kotlin.data.MeInfoBean;
import com.flashcash.kotlin.data.ProductBean;
import com.flashcash.kotlin.data.SkyPayRepaymentInfo;
import com.flashcash.kotlin.data.SysDictBean;
import com.flashcash.kotlin.data.UserBankInfo;
import com.flashcash.kotlin.data.WithdrawChannel;
import com.flashcash.solu.bean.AppEntity;
import com.flashcash.solu.bean.BankByCategoryBean;
import com.flashcash.solu.bean.CategoryBean;
import com.flashcash.solu.bean.ContactInfoBean;
import com.flashcash.solu.bean.DepositMethodsBean;
import com.flashcash.solu.bean.DepositResponseBean;
import com.flashcash.solu.bean.EmploymentServerBean;
import com.flashcash.solu.bean.HistoryLoanAppInfoBean;
import com.flashcash.solu.bean.IDType;
import com.flashcash.solu.bean.LatestLoanAppBean;
import com.flashcash.solu.bean.LoginRequestBean;
import com.flashcash.solu.bean.LoginTokenResponse;
import com.flashcash.solu.bean.MarketApp;
import com.flashcash.solu.bean.MsgInboxBean;
import com.flashcash.solu.bean.PersonalInfoServerBean;
import com.flashcash.solu.bean.ProgressBean;
import com.flashcash.solu.bean.RecordFilesResponse;
import com.flashcash.solu.bean.RegionBean;
import com.flashcash.solu.bean.ResponseErrorBody;
import com.flashcash.solu.bean.SkypayBanksAddressBean;
import com.flashcash.solu.bean.SkypayBanksBean;
import com.flashcash.solu.bean.ThirdPartDataBean;
import com.flashcash.solu.bean.UserInfoEntity;
import com.flashcash.solu.bean.YWUser;

import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;

import okhttp3.ResponseBody;
import retrofit2.adapter.rxjava.Result;
import retrofit2.http.Body;
import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.GET;
import retrofit2.http.Header;
import retrofit2.http.Headers;
import retrofit2.http.POST;
import retrofit2.http.PUT;
import retrofit2.http.Path;
import retrofit2.http.Query;
import rx.Observable;

/**
 * Created by localuser on 2017/2/27.
 */

public interface UserApi {

    @FormUrlEncoded
    @POST("auth/login/sms")
    Observable<BasicAck> sendSms(@Field("mobile") String mobile);

    @FormUrlEncoded
    @POST("auth/login")
    Observable<LoginTokenResponse> login(@Header("X-SMS-CODE") LoginRequestBean.SMSCode smsCode,
                                         @Header("X-CAPTCHA-SID") LoginRequestBean.CaptchaSID
                                                 captchaSid,
                                         @Header("X-CAPTCHA") LoginRequestBean.Captcha captcha,
                                         @Field("mobile") LoginRequestBean.Mobile mobile,
                                         @Field("code") String code);

    @Deprecated
    @POST("auth/logout")
    Observable<ResponseBody> logout(@Query("token") String token,
                                    @Query("refreshToken") String refreshToken);

    @FormUrlEncoded
    @PUT("record/employment")
    Observable<ResponseBody> submitEmploymentInfo(@Field("companyName") String companyName,
                                                  @Field("companyProvince") String companyProvince,
                                                  @Field("companyCity") String companyCity,
                                                  @Field("companyDistrict") String companyDistrict,
                                                  @Field("companyArea") @Nullable String
                                                          companyArea,
                                                  @Field("companyAddress") String companyAddress,
                                                  @Field("companyPhone") String companyPhone,
                                                  @Field("profession") String profession,
                                                  @Field("salary") String salary,
                                                  @Header("X-AUTH-TOKEN") String token);

    @FormUrlEncoded
    @PUT("record/personalinfo")
    Observable<ResponseBody> submitPersonalInfo(@Field("firstName") String firstName,
                                                @Field("middleName") String middleName,
                                                @Field("lastName") String lastName,
                                                @Field("fullName") String fullName,
                                                @Field("credentialType") String credentialType,
                                                @Field("birthday") String birthday,
                                                @Field("credentialNo") String credentialNo,
                                                @Field("familyNameInLaw") String familyNameInLaw,
                                                @Field("gender") String gender,
                                                @Field("province") String province,
                                                @Field("city") String city,
                                                @Field("district") String district,
                                                @Field("area") @Nullable String area,
                                                @Field("address") String address,
                                                @Field("lastEducation") String lastEducation,
                                                @Field("maritalStatus") String maritalStatus,
                                                @Field("childrenNumber") String childrenNumber,
                                                @Field("residenceDuration") String residenceDuration,
                                                @Field("facebookId") String facebookId,
                                                @Header("X-AUTH-TOKEN") String token);

    @FormUrlEncoded
    @PUT("record/contact")
    Observable<ResponseBody> submitContactInfo(@Field("parentName") String parentName,
                                               @Field("parentMobile") String parentMobile,
                                               @Field("friendName") String friendName,
                                               @Field("friendMobile") String friendMobile,
                                               @Header("X-AUTH-TOKEN") String token);

    @GET("loanapp/latest/v2")
    Observable<LatestLoanAppBean> getLatestLoanApp(@Header("X-AUTH-TOKEN") String token, @Query
            ("type") String type);

    @FormUrlEncoded
    @POST("loanapp")
    Observable<ResponseBody> applyLoanApp(@Field("loanType") String loanType,
                                          @Field("amount") String amount,
                                          @Field("period") String period,
                                          @Field("periodUnit") String periodUnit,
                                          @Field("bankCode") String bankCode,
                                          @Field("cardNo") String cardNo,
                                          @Field("applyFor") String applyFor,
                                          @Field("applyChannel") String applyChannel,
                                          @Field("applyPlatform") String applyPlatform,
                                          @Field("couponId") long couponId,
                                          @Header("X-AUTH-TOKEN") String token
            , @Header("imei") String imei
    );

    @POST("auth/refresh")
    Observable<Result<LoginTokenResponse>> refreshToken(@Query("mobile") String mobile,
                                                        @Query("refreshToken") String refreshToken);

    @GET("region/{level}/{id}")
    Observable<RegionBean> getRegion(@Path("level") String level,
                                     @Path("id") int id

    );

    @FormUrlEncoded
    @POST("auth/logout")
    Observable<ResponseBody> logout(@Field("token") String token);

    @GET("loanapp/deposit/methods")
    Observable<DepositMethodsBean> getDepostMethods(@Header("X-AUTH-TOKEN") String token);

    @POST("loanapp/deposit")
    Observable<DepositResponseBean> doDeposit(@Query("loanAppId") String loanAppId,
                                              @Query("currency") String currency,
                                              @Query("depositMethod") String method,
                                              @Query("amount") double amout,
                                              @Header("X-AUTH-TOKEN") String token
    );

    @Deprecated
    @FormUrlEncoded
    @PUT("loanapp/deposit")
    Observable<ResponseBody> sendPayCode(@Field("depositId") String loanAppId,
                                         @Field("outerTransactionId") String paymentCode,
                                         @Header("X-AUTH-TOKEN") String token
    );

    @GET("loanapp/all/v2")
    Observable<List<HistoryLoanAppInfoBean>> getLoanAppAll(@Header("X-AUTH-TOKEN") String token);

    @GET("record/progress")
    Observable<ProgressBean> progress(@Header("X-AUTH-TOKEN") String token);

    @FormUrlEncoded
    @POST("loanapp/cancel")
    Observable<ResponseBody> cancelLoan(@Field("loanAppId") String loanAppId,
                                        @Header("X-AUTH-TOKEN") String token);

    @GET("info/inbox/all")
    Observable<List<MsgInboxBean>> getMsgInbox(@Header("X-AUTH-TOKEN") String token);

    @FormUrlEncoded
    @POST("info/inbox/read")
    Observable<ResponseBody> sendReadMsg(@Field("msgId") String msgId,
                                         @Header("X-AUTH-TOKEN") String token);

    @GET("loanapp/qualification")
    Observable<ResponseErrorBody> isQualification(@Header("X-AUTH-TOKEN") String token);

    @GET("record/contact")
    Observable<ContactInfoBean> getContactInfo(@Header("X-AUTH-TOKEN") String token);

    @GET("record/employment")
    Observable<EmploymentServerBean> getEmploymentInfo(@Header("X-AUTH-TOKEN") String token);

    @GET("record/personalinfo")
    Observable<PersonalInfoServerBean> getPersonalInfo(@Header("X-AUTH-TOKEN") String token);


    @GET("chat/account")
    Observable<YWUser> getChatUserInfo(@Header("X-AUTH-TOKEN") String token);

    /**
     * obtain latest version
     *
     * @return
     */
    @GET("version/latest")
    Observable<ResponseBody> getVersionInfo();


    /**
     * obtain loan range(min  ---  max)
     *
     * @return
     */
    @GET("loanapp/range")
    Observable<LoanRange> getLoanRange();

    @GET("invitation/mine/code")
    Observable<ResponseBody> getInviteCode(@Header("X-AUTH-TOKEN") String token);

    @GET("invitation/mine/invitee")
    Observable<InviteeBean> getInviteInfo(@Header("X-AUTH-TOKEN") String token);

    @GET("coupon/available")
    Observable<List<CouponBean>> getAvailableCoupon(@Header("X-AUTH-TOKEN") String token);

    @GET("coupon/used")
    Observable<List<CouponBean>> getUsedCoupon(@Header("X-AUTH-TOKEN") String token);

    @GET("coupon/outdated")
    Observable<List<CouponBean>> getOutdatedCoupon(@Header("X-AUTH-TOKEN") String token);

    @GET("info/infocenter")
    Observable<MeInfoBean> getMeInfo(@Header("X-AUTH-TOKEN") String token);

    @GET("banner")
    Observable<ArrayList<ActivityInfoBean>> getActivityList();

    @GET("invitation/mine/invitee/list")
    Observable<ArrayList<InviteePersonBean>> getInvitedList(@Header("X-AUTH-TOKEN") String token);

    @GET("loanapp/repayment-amount-detail")
    Observable<LoaningAmoutBean> getLoanAmoutData(@Query("principal") double amount,
                                                  @Query("period") int day,
                                                  @Query("periodUnit") String periodUnit,
                                                  @Query("productId") long productId);

    @GET("record/ktp-photo")
    Observable<RecordFilesResponse> getKtpImg(@Header("X-AUTH-TOKEN") String token);

    @GET("record/employ-photo")
    Observable<RecordFilesResponse> getJobImg(@Header("X-AUTH-TOKEN") String token);

    @PUT("loanapp/{loanAppId}/bank")
    Observable<ResponseBody> addBank(
            @Path("loanAppId") String loanAppId,
            @Query("bankCode") @NotNull String bankCode,
            @Query("cardNo") String cardNo,
            @Query("applyFor") String applyFor,
            @Query("cardMonth") String cardMonth,
            @Query("cardYear") String cardYear,
            @Query("fullName") String fullName,
            @Query("email") String email,
            @Query("applyChannel") @NotNull String applyChannel,
            @Query("applyPlatform") String android,
            @Query("couponId") long couponId,
            @Header("X-AUTH-TOKEN") String token);

    @GET("loanapp/skypay-withDrawChannels")
    Observable<List<WithdrawChannel>> getSkyPayWithdrawChannles(@Query("version") int version);

    @PUT("loanapp/{loanAppId}/skypay-info")
    Observable<ResponseBody> addSkypayInfo(
            @Path("loanAppId") String loanAppId,
            @Query("withDrawChannel") @NotNull String withdrawChannel,
            @Query("accountNo") String accountNo,
            @Query("bankNo") String bankNo,
            @Query("bankProvince") String bankProvince,
            @Query("bankCity") String bankCity,
            @Header("X-AUTH-TOKEN") String token);

    @FormUrlEncoded
    @POST("auth/login_account_kit")
    Observable<LoginTokenResponse> login_new(
            @Field("mobile") String mobile,
            @Field("auth_code") String auth_code);

    @GET("bank/support")
    Observable<List<BankBean>> requestBankList();

    @GET("record/bankcard")
    Observable<UserBankInfo> getBankCardInfo(@Header("X-AUTH-TOKEN") String token);

    @GET("loanapp/skypay/repayment-info")
    Observable<SkyPayRepaymentInfo> getSkyPayRepaymentInfo(@Header("X-AUTH-TOKEN") String token,
                                                           @Query("loanAppId") Long loanAppId);

    @GET("loanapp/deposit/categorys")
    Observable<ArrayList<CategoryBean>> categorys(@Header("X-AUTH-TOKEN") String token);

    @GET("loanapp/deposit/bankByCategory")
    Observable<ArrayList<BankByCategoryBean>> bankByCategory(@Header("X-AUTH-TOKEN") String token,
                                                             @Query("paymentCategory") String
                                                                     paymentCategory);

    @GET("sysdict/{type}")
    Observable<ArrayList<SysDictBean>> sysDict(@Path("type") String type);

    @GET("record/files")
    Observable<RecordFilesResponse> recordFiles(@Header("X-AUTH-TOKEN") String token);

    @GET("loanapp/product")
    Observable<ArrayList<ProductBean>> getProducts(@Header("X-AUTH-TOKEN") String token);

    @GET("loanapp/product_default")
    Observable<ArrayList<ProductBean>> getProductsDefault();

//    @FormUrlEncoded
    @POST("http://flashcash.ph/iapi/querymarket")
    @Headers("Content-Type:application/json")
//    Observable<ResponseBody> getMarket(@Field("appName") String appName);
    Observable<MarketApp> getMarket(@Body AppEntity appName);
//    Observable<MarketApp> getMarket(@Field("appName") String appName);

    @GET("loanapp/display")
    Observable<DisplayBean> display();

    @GET("setting/me")
    Observable<HelpCenterUrlAndHotlineBean> getHelpCenterUrlAndHotline();

    @GET("setting/main-banners")
    Observable<ArrayList<BannerUrlBean>> getBannerUrl();

    @FormUrlEncoded
    @PUT("record/firebase_token")
    Observable<ResponseBody> uploadFirebaseToken(@Field("firebase_token") String token);

    @PUT("{loanAppId}/skypay-info")
    Observable<ResponseBody> getSkypayInfo(@Query("accountNo") int accountNo,@Query("bankNo") String bankNo,
                                           @Query("bankProvince") String bankProvince,@Query("bankCity") String bankCity);


    @GET("loanapp/skypay-banks")
    Observable<ArrayList<SkypayBanksBean>> getSkypayBanks();

    @GET("loanapp/credentialTypeArray")
    Observable<ArrayList<IDType>> getCredentialTypeArray();

    @GET("loanapp/skypay-bank-address")
    Observable<ArrayList<SkypayBanksAddressBean>> getSkyPayBankAddress(@Query("parentId") int parentId);

    /**
     * 绑定的第三方账号
     */
    @GET("record/thirdparty_data")
    Observable<ThirdPartDataBean> getThirdPartAccount(@Header("X-AUTH-TOKEN") String token);

    /**
     * 提交第三方数据
     */
    @PUT("record/thirdparty_data")
    Observable<ResponseBody> submitThirdPartData(@Header("X-AUTH-TOKEN") String token,
                                                 @Query("dataChannel") String dataChannel,
                                                 @Query("dataType") String dataType,
                                                 @Query("taskId") String taskId,
                                                 @Query("credentialNo") String credentialNo,
                                                 @Query("realName") String realName,
                                                 @Query("mobile") String mobile,
                                                 @Query("passbackparams") String passbackparams);

    @POST("http://flashcash.ph/iapi/adduserinfo")
    @Headers("Content-Type:application/json")
    Observable<ResponseBody> addUserInfo(@Body UserInfoEntity userInfoEntity);

}



